package com.zrwl.poscloud.core.restapi.admin.baseInfo;
import com.alibaba.fastjson.JSONObject;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.xo.service.AdminService;
import com.zrwl.poscloud.xo.service.DeptAdminRService;
import com.zrwl.poscloud.xo.vo.AdminVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zrwl.poscloud.xo.service.EmployeeRecordService;
import com.zrwl.poscloud.xo.vo.EmployeeRecordVO;
/**
 * 人员简历 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-02-27
 */
@RestController
@Api(value = "人员简历相关接口", tags = {"人员简历相关接口"})
@RequestMapping("/employeeRecord")
@Slf4j
public class EmployeeRecordRestApi {
    @Autowired
    private EmployeeRecordService employeeRecordService;
    @Autowired
    private AdminService adminService;
    @Autowired
    private DeptAdminRService deptAdminRService;
    @AuthorityVerify
    @ApiOperation(value = "获取人员简历列表", notes = "获取人员简历列表", response = String.class)
    @PostMapping("/getList")
    public JSONObject getList(@Validated({GetList.class}) @RequestBody EmployeeRecordVO employeeRecordVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取人员简历列表: {}", employeeRecordVO);
        AdminVO adminVO = adminService.getMe();
        if (adminVO.isCompany()) {
            if (employeeRecordVO.getCompanyCode() == null)
                employeeRecordVO.setCompanyCode(adminVO.getCompanyCode());
        } else {
            return ResultUtil.errorWithJSONMessage("仅商户用户支持此功能");
        }
        employeeRecordVO.setDeptRoleTree(deptAdminRService.getMyDeptRoleTreeCode());
        return ResultUtil.successWithJSONData(employeeRecordService.getPageList(employeeRecordVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取人员简历列表", notes = "获取人员简历列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody EmployeeRecordVO employeeRecordVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取人员简历列表: {}", employeeRecordVO);
        return ResultUtil.successWithData(employeeRecordService.getAllList(employeeRecordVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增人员简历")    @ApiOperation(value = "新增人员简历", notes = "新增人员简历", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody EmployeeRecordVO employeeRecordVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增人员简历: {}", employeeRecordVO);
        return employeeRecordService.add(employeeRecordVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改人员简历")    @ApiOperation(value = "修改人员简历", notes = "修改人员简历", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody EmployeeRecordVO employeeRecordVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改人员简历: {}", employeeRecordVO);
        return employeeRecordService.edit(employeeRecordVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除人员简历")    @ApiOperation(value = "删除人员简历", notes = "删除人员简历", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody EmployeeRecordVO employeeRecordVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除人员简历: {}", employeeRecordVO);
        return employeeRecordService.delete(employeeRecordVO);
    }

}
